//
// Created by de on 4/6/21.
//
#include <SqlController/dao/SqlSqliteDao.h>
#include "gtest/gtest.h"
class SqlTest: public ::testing::Test {
protected:
    virtual ~SqlTest() {
        // You can do clean-up work that doesn't throw exceptions here.
    }

    // If the constructor and destructor are not enough for setting up
    // and cleaning up each test, you can define the following methods:
    virtual void SetUp() {
        // Code here will be called immediately after the constructor (right
        // before each test).
        EXPECT_EQ(true , my.connect());
        using namespace HsLog;
        SqlLoger::initHsLog();

    }

    virtual void TearDown() {
        // Code here will be called immediately after each test (right
        // before the destructor).
    }

    // Objects declared here can be used by all tests in the test case for Project1.
    SqlSqliteDao my;
public:
    SqlTest() {
        // You can do set-up work for each test here.
    }
};


TEST_F(SqlTest, Connect) {

    EXPECT_EQ(true , my.checkTableExist());

}

TEST_F(SqlTest, Remove) {

    EXPECT_EQ(true , my.connect());
    my.removeAll();
}

TEST_F(SqlTest, Insert) {
    WorkResult workResult{-1, 0.3,0.6,0.2,false};

    my.insertObject(workResult);
}


TEST_F(SqlTest, getALl) {
    std::vector<WorkResult> v_WorkGroup = my.getAll();
    spdlog::info("");
    for(auto it: v_WorkGroup)
    {
        spdlog::info(it.to_string());
    }
    EXPECT_TRUE(v_WorkGroup.size() > 0);
}

TEST_F(SqlTest, LOOP) {
    for(int i = 0;i < 3; i++)
    {
        WorkResult workResult{-1, 0.3,0.6,0.2,false};
        my.insertObject(workResult);
        std::vector<WorkResult> v_WorkGroup = my.getAll();
        for(auto it: v_WorkGroup)
        {
            spdlog::info(it.to_string());
        }
        spdlog::info("--------------------------------");

    }

}

int main(int argc, char* argv[])
{
    ::testing::InitGoogleTest(&argc, argv);
 //std::cout << "1"<<std::endl;
    return RUN_ALL_TESTS();
}